//
//  BYNetworkHelper.h
//  BTCBOX
//
//  Created by biyunkeji on 2017/11/29.
//  Copyright © 2017年 jianfengChen. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "NetworkCache.h"
#import "NetAPIClient.h"
#import "UIImage+AFNetworking.h"

@interface NetworkHelper : NSObject <UIAlertViewDelegate> {
    
    UIAlertView *_alertView;//安全验证码的提示框
    
}

/** 请求成功且错误码为0的Block */
typedef void(^HttpRequestSuccessResponseCodeCorrect)(id response, NSString *responseCodeStr);
/** 请求成功且错误码不为0的Block */
typedef void(^HttpRequestSuccessResponseCodeWrong)(id response, NSString *responseCodeStr);
/** 请求失败的Block */
typedef void(^HttpRequestFailed)(NSError *error);

/** 缓存的Block */
typedef void(^HttpRequestCache)(id responseCache);
/** 上传或者下载的进度, Progress.completedUnitCount:当前大小 - Progress.totalUnitCount:总大小*/
typedef void (^HttpProgress)(NSProgress *progress);

/**
 *  请求超时时间
 */
+(void)timeoutInterval:(NSTimeInterval)timeInterval;

+ (NetAPIClient *)manager;

/**
 GET
 */
+ (NSURLSessionTask *)GET:(NSString *)URL parameters:(id)parameters
                    successResponseCodeCorrect:(HttpRequestSuccessResponseCodeCorrect)successResponseCodeCorrect successResponseCodeWrong:(HttpRequestSuccessResponseCodeWrong)successResponseCodeWrong
                    failure:(HttpRequestFailed)failure showError:(BOOL )error;


/**
 POST
 */
+ (NSURLSessionTask *)POST:(NSString *)URL
                parameters:(id)parameters
                   successResponseCodeCorrect:(HttpRequestSuccessResponseCodeCorrect)successResponseCodeCorrect successResponseCodeWrong:(HttpRequestSuccessResponseCodeWrong)successResponseCodeWrong
                   failure:(HttpRequestFailed)failure showError:(BOOL )error;
/**
 *  上传图片文件
 *
 *  @param URL        请求地址
 *  @param parameters 请求参数
 *  @param images     图片数组
 *  @param name       文件对应服务器上的字段
 *  @param fileName   文件名
 *  @param mimeType   图片文件的类型,例:png、jpeg(默认类型)....
 *  @param progress   上传进度信息
 *  @param successResponseCodeCorrect       请求成功且返回码正确的回调（code = 0）
 *  @param successResponseCodeWrong         请求成功且返回码错误的回调（code != 0）
 *  @param failure    请求失败的回调
 *
 *  @return 返回的对象可取消请求,调用cancle方法
 */
+ (__kindof NSURLSessionTask *)uploadWithURL:(NSString *)URL
                                  parameters:(NSDictionary *)parameters
                                      images:(NSArray<UIImage *> *)images
                                        name:(NSString *)name
                                    fileName:(NSString *)fileName
                                    mimeType:(NSString *)mimeType
                                    progress:(HttpProgress)progress
                                     successResponseCodeCorrect:(HttpRequestSuccessResponseCodeCorrect)successResponseCodeCorrect successResponseCodeWrong:(HttpRequestSuccessResponseCodeWrong)successResponseCodeWrong
                                     failure:(HttpRequestFailed)failure;

/**
 *  下载文件
 *
 *  @param URL      请求地址
 *  @param fileDir  文件存储目录(默认存储目录为Download)
 *  @param progress 文件下载的进度信息
 *  @param success  下载成功的回调(回调参数filePath:文件的路径)
 *  @param failure  下载失败的回调
 *
 *  @return 返回NSURLSessionDownloadTask实例，可用于暂停继续，暂停调用suspend方法，开始下载调用resume方法
 */
+ (__kindof NSURLSessionTask *)downloadWithURL:(NSString *)URL
                                       fileDir:(NSString *)fileDir
                                      progress:(HttpProgress)progress
                                       success:(void(^)(NSString *filePath))success
                                       failure:(HttpRequestFailed)failure;
/**
 *  取消所有的网络请求
 */
+ (void)cancelAllOperations;

+ (NSString *)domainWithHost:(NSString *)url;

@end
